package bean;

import java.util.List;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import model.ProductM;
import object.Product;
import object.ProductDetail;
import object.ReturnBool;
import tpInterface.IProduct;

/**
 *
 * @author SonTT
 */
@ManagedBean
@RequestScoped
public class ProductBean implements IProduct {

    private static final Logger LOG = Logger.getLogger(ProductBean.class.getName());
    private ProductM productM;
    private ProductDetail productDetail;
    private List<ProductDetail> pList;
    private String category;

    public List<ProductDetail> getpList() {
        return pList;
    }

    public ProductDetail getProductDetail() {
        return productDetail;
    }

    /**
     * Creates a new instance of ProductBean
     */
    public ProductBean() {
        productM = new ProductM();
    }

    @Override
    public List<ProductDetail> getProducts() {
        return productM.getProducts();
    }

    @Override
    public ReturnBool addProduct(Product product) {
        return productM.addProduct(product);
    }

    @Override
    public ReturnBool editProduct(Product product) {
        return productM.editProduct(product);
    }

    @Override
    public ReturnBool deleteProduct(String productID) {
        return productM.deleteProduct(productID);
    }

    @Override
    public ReturnBool deleteProducts(String[] productIDs) {
        return productM.deleteProducts(productIDs);
    }

    @Override
    public List<ProductDetail> searchProduct(String keyword) {
        return productM.searchProduct(keyword);
    }

    @Override
    public ProductDetail getProductDetailByProductID(String productID) {
        return productM.getProductDetailByProductID(productID);
    }

    @Override
    public List<ProductDetail> getProductDetailByCategoryID(String categoryID) {
        return productM.getProductDetailByCategoryID(categoryID);
    }

    public String showDetail(ProductDetail productDetail) {
        this.productDetail = productDetail;
        return "productDetail";
    }

    public String showProductDetails(String categoryID) {
        this.pList = this.getProductDetailByCategoryID(categoryID);
        return "productByCategory";
    }

    public String getIdString(int id) {
        String s = ((Integer) id).toString();
        return s;
    }
}
